package leetcode.code1871;

import java.util.LinkedList;
import java.util.Queue;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public boolean canReach(String s, int minJump, int maxJump) {
		char[] cs = s.toCharArray();
		int len = cs.length;
		int[] sums = new int[len];
		sums[0] = 1;
		int p = 1;
		while (p < len) {
			// 01111111011110
			int cur = cs[p] - '0';
			int ok = 0;
			if (cur == 0) {
				int l = p - maxJump, r = p - minJump;
				if (r >= 0) {
					int sum = 0;
					if (l <= 0) {
						sum = sums[r];
					} else {
						sum = sums[r] - sums[l - 1];
					}
					if (sum > 0) {
						ok = 1;
						if (p == len - 1) {
							return true;
						}
					}
				}
			}
			sums[p] = sums[p - 1] + ok;
			p++;
		}
		return false;
	}

	@Override
	public void debug4() {
		H.compare(true, this.canReach("01111111011110", 1, 9));
		H.compare(false, this.canReach("0000000000", 8, 8));
		H.compare(true, this.canReach("011010", 2, 3));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
